package com.itgaohe.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itgaohe.dao.entity.VoucherOrder;
import org.apache.ibatis.annotations.*;

/**
 * 优惠券订单接口
 */
@Mapper
public interface VoucherOrderMapper extends BaseMapper<VoucherOrder> {
    /**
     * 根据获取到的参数插入订单信息
     * @param voucherOrder
     * @return
     */
    @Insert("INSERT INTO tb_voucher_order(id, user_id, voucher_id, pay_type, status, create_time, update_time) " +
            "VALUES(#{id}, #{userId}, #{voucherId}, #{payType}, #{status}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(VoucherOrder voucherOrder);

    // 检查用户是否已购买过该优惠券
    @Select("SELECT COUNT(id) FROM tb_voucher_order " +
            "WHERE user_id = #{userId} AND voucher_id = #{voucherId}")
    int countUserOrders(@Param("userId") Long userId, @Param("voucherId") Long voucherId);
}



